home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / CBGETKCU.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  103 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbgetkcu.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STRING
  11. #include <string.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <blkio.h>
  16. #include <btree.h>
  17.  
  18. /* local headers */
  19. #include "cbase_.h"
  20.  
  21. /*man---------------------------------------------------------------------------
  22. NAME
  23.      cbgetkcur - get cbase key cursor
  24.  
  25. SYNOPSIS
  26.      #include <cbase.h>
  27.  
  28.      int cbgetkcur(cbp, field, cbkposp)
  29.      cbase_t *cbp;
  30.      int field;
  31.      cbkpos_t *cbkposp;
  32.  
  33. DESCRIPTION
  34.      The cbgetkcur function gets the position of the key cursor of the
  35.      specified field in cbase cbp.  The cursor position is returned in
  36.      the location pointed to by cbkposp.
  37.  
  38.      cbgetkcur will fail if one or more of the following is true:
  39.  
  40.      [EINVAL]       cbp is not a valid cbase pointer.
  41.      [EINVAL]       field is not a valid field number for cbase cbp.
  42.      [EINVAL]       cbkposp is the NULL pointer.
  43.      [CBELOCK]      cbp is not locked.
  44.      [CBENOPEN]     cbp is not open.
  45.  
  46. SEE ALSO
  47.      cbgetrcur, cbsetkcur.
  48.  
  49. DIAGNOSTICS
  50.      Upon successful completion, a value of 0 is returned.  Otherwise,
  51.      a value of -1 is returned, and errno set to indicate the error.
  52.  
  53. ------------------------------------------------------------------------------*/
  54. #ifdef AC_PROTO
  55. int cbgetkcur(cbase_t *cbp, int field, cbkpos_t *cbkposp)
  56. #else
  57. int cbgetkcur(cbp, field, cbkposp)
  58. cbase_t *cbp;
  59. int field;
  60. cbkpos_t *cbkposp;
  61. #endif
  62. {
  63.     btpos_t btpos;
  64.  
  65.     /* initialize automatic aggregates */
  66.     memset(&btpos, 0, sizeof(btpos));
  67.  
  68.     /* validate arguments */
  69.     if (!cb_valid(cbp) || cbkposp == NULL) {
  70.         errno = EINVAL;
  71.         return -1;
  72.     }
  73.  
  74.     /* check if not open */
  75.     if (!(cbp->flags & CBOPEN)) {
  76.         errno = CBENOPEN;
  77.         return -1;
  78.     }
  79.  
  80.     /* validate arguments */
  81.     if (field < 0 || field >= cbp->fldc) {
  82.         errno = EINVAL;
  83.         return -1;
  84.     }
  85.  
  86.     /* check if not locked */
  87.     if (!(cbp->flags & CBLOCKS)) {
  88.         errno = CBELOCK;
  89.         return -1;
  90.     }
  91.  
  92.     /* get key cursor position */
  93.     if (btgetcur(cbp->btpv[field], &btpos) == -1) {
  94.         CBEPRINT;
  95.         return -1;
  96.     }
  97.  
  98.     /* load return argument */
  99.     memcpy(cbkposp, &btpos, sizeof(cbkpos_t));
  100.  
  101.     return 0;
  102. }
  103.